<template>
	<view class="home">
		<!-- 轮播区 -->
		<swiper indicator-dots="true" indicator-color="#CCCCCC" indicator-active-color=$shop-color circular="true" autoplay="true" interval="4000">
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区 -->
		<view class="nav">
			<view class="nav_item" v-for="item in navs" :key="item.title">
				<!-- 字体图标 -->
				<view :class="item.icon" @click="navItemClick(item.path)"></view>
				<!-- 文字 -->
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐商品区 -->
		<view class="hot_goods">
			<view class="tit">推荐商品</view>
			<!-- 商品列表区 -->
			<goodsList :goods="HotGoods"></goodsList>
		</view>
	</view>
</template>
<script>
	import goodsList from "../components/goods-list/goods-list"//引入商品列表组件
	export default {
		data() {
			return {
				swipers:[],
				HotGoods:[],
				navs:[
					{
						icon:"iconfont icon-ziyuan",
						title:"黑马超市",
						path:"/pages/goods/goods"
					},
					{
						icon:"iconfont icon-guanyuwomen",
						title:"联系我们",
						path:"/pages/contact/contact"
					},
					{
						icon:"iconfont icon-tupian",
						title:"社区图片",
						path:"/pages/pics/pics"
					},
					{
						icon:"iconfont icon-shipin",
						title:"学习视频",
						path:"/pages/videos/videos"
					}
				]
			}
		},
		components:{
			goodsList
		},
		onLoad() {
			this.getSwipers()
			this.getHotGoods()
		},
		methods: {
			async getSwipers(){//获取轮播图数据
				const res = await this.$myRequest({
					url:'/api/getLunbo.json'
				})
				this.swipers = res.data.message
			},
			async getHotGoods(){// 获取"推荐商品"列表数据
				const HotGoods = await this.$myRequest({
					url:'/api/getGoods.json'
				})
				this.HotGoods = HotGoods.data.message
			},
			//导航点击事件
			navItemClick(url){
				// if(url=="../goods/goods"){//跳转到goods页面，传商品数据
				// 	url='../goods/goods?data=qqq'
				// }
				uni.navigateTo({
					url
				})
			}
	}
}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	// 导航区
	.nav{
		// 一行显示
		display: flex;// flex布局
		.nav_item{
			width: 25%;
			text-align: center;//字体图标居中
			view{
				width: 120rpx;
				height: 120rpx;
				background: $shop-color;//背景
				border-radius: 60rpx;//原型
				margin: 10px auto; //居中，上下有间距
				line-height: 120rpx;//字体图标的行高
				color: #FFFFFF;//字体图标的颜色
				font-size: 50rpx;//字体图标的大小
			}
			.icon-tupian{
				font-size: 45rpx;
			}
			text{
				font-size: 30rpx;
			}
		}
	}
	// 推荐商品
	.hot_goods{
		background: #eee;//背景色
		margin-top: 10px;
		overflow: hidden;
		.tit{
			height: 50px;
			line-height: 50px;
			color:$shop-color ;
			text-align: center;//居中
			letter-spacing: 20px;//字之间的间距
			background: #FFFFFF;//白色背景色
			margin:7rpx 0//上下10rpx,左右0间距
		}
	}

</style>
